package game;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class MainMenu extends Menu {
	private Color back = new Color(0, 80, 0);
	
	public MainMenu(GrandeCanvas c){
		super(c);
		init();
	}
	
	public void init(){
		elements.add(new MenuButton(this, 1200, 400, 250, 50, "Play!", 30, null){
			public void clicked(MouseEvent e){
				getCanvas().resumeGame();
			}
		});
		elements.add(new MenuButton(this, 1200, 500, 250, 50, "Quit", 30, null){
			public void clicked(MouseEvent e){
				canvas.quitGame();
			}
		});
	}
	
	public void draw(){
		if(canvas.buffer == null){
			canvas.buffer = canvas.createImage(canvas.fwidth, canvas.fheight);
		}else{
			canvas.bufGraphics = (Graphics2D)canvas.buffer.getGraphics();
		}
	}
	
	public void updateMenu(){
        for(MenuItem e: elements){
        	if(e.contains(canvas.relMousePos)){
        		e.onHover();
        	}else{
        		e.offHover();
        	}
        }
        super.updateMenu();
    }
	
	public void mousePress(MouseEvent e){
		for(MenuItem i: elements){
			if(i.contains(e.getX(), e.getY())){
				i.clicked(e);
			}
		}
	}
	
	public BufferedImage getImage(String s){
		try{
			return ImageIO.read(new File(s));
		}catch (Exception e){
			return null;
		}
	}
}
